// XtremeMDIFrameWnd.cpp : implementation file
//

#include "stdafx.h"
#include "XtremeFrame.h"
#include "XtremeMDIFrameWnd.h"
#include "SysLocalResource.h"

// CXtremeMDIFrameWnd

IMPLEMENT_DYNCREATE(CXtremeMDIFrameWnd, CXTPMDIFrameWnd)

CXtremeMDIFrameWnd::CXtremeMDIFrameWnd()
: m_ShowType(0)
, pCommandBars(NULL)
{
}

CXtremeMDIFrameWnd::~CXtremeMDIFrameWnd()
{
}


void CXtremeMDIFrameWnd::OnSize(UINT nType, int cx, int cy)
{
	CXTPMDIFrameWnd::OnSize(nType, cx, cy);
	// TODO: Add your message handler code here
}


BOOL CXtremeMDIFrameWnd::CreateRibbonBar()
{
	return TRUE;
}

BEGIN_MESSAGE_MAP(CXtremeMDIFrameWnd, CXTPMDIFrameWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
END_MESSAGE_MAP()

int CXtremeMDIFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

	if (CXTPMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	//ModifyStyle(WS_CAPTION,   NULL,   SWP_DRAWFRAME); 
	//ModifyStyle(WS_BORDER,   NULL,   SWP_DRAWFRAME); 
	//ModifyStyle(WS_THICKFRAME,   NULL,   SWP_DRAWFRAME); 	

	if (!CreateStatusBar())
		return -1;

	
	if (!InitCommandBars())
		return -1;
	
	
	m_bShowWorkspace = TRUE;

	m_wndClient.Attach(this, FALSE);
	m_wndClient.GetToolTipContext()->SetStyle(xtpToolTipResource);


	switch(m_ShowType)
	{
	case 0:
		break;
	case 1:		
		pCommandBars = GetCommandBars();
		pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
		pCommandBars->GetCommandBarsOptions()->bToolBarAccelTips = TRUE;
		pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
		XTPPaintManager()->SetTheme(m_theme);
		{
			CXTPToolTipContext* pToolTipContext = GetCommandBars()->GetToolTipContext();
			pToolTipContext->SetStyle(xtpToolTipResource);
			pToolTipContext->ShowTitleAndDescription();
			pToolTipContext->SetMargin(CRect(2, 2, 2, 2));
			pToolTipContext->SetMaxTipWidth(180);
			pToolTipContext->SetFont(pCommandBars->GetPaintManager()->GetIconFont());
		}
		LoadIcons();
		if (!CreateRibbonBar())
		{
			TRACE0("Failed to create ribbon\n");
			return -1;
		}		
		LoadCommandBars(_T("CommandBars"));
		break;
	default:
		break;
	}

	////HMODULE hModule = AfxLoadLibrary(m_csStylesPath + _T("Office2007.dll"));
	////((CXTPOffice2007Theme*)pCommandBars->GetPaintManager())->SetImageHandle(hModule);
	////////////////////////////////////////////////////////////////////////////	
	//// IMPORTANT:
	//// Ribbon bitmaps resources by default located in application executable. 
	////
	//// You also can specify handle to find ribbon resources:
	////((CXTPOffice2007Theme*)XTPPaintManager())->SetImageHandle(hHandle);


	
	m_paneManager.InstallDockingPanes(this);
	m_paneManager.SetTheme(m_docktheme);
	{
		CSysLocalResource res(theApp.m_hInstance);
		m_paneManager.CreatePane(ID_OUTLOOK_BAR, CRect(0, 0, 150, 120), xtpPaneDockLeft);
	}

	if (!InitializeOutlookBar())
		return FALSE;
	
	
	return 0;
}


// CreateStatusBar
int CXtremeMDIFrameWnd::CreateStatusBar(void)
{
	return 1;
}


// CreateStatusBar
void CXtremeMDIFrameWnd::LoadIcons(void)
{
}


void CXtremeMDIFrameWnd::SetTheme(XTPPaintTheme nTheme)
{
	m_nTheme = nTheme;

	XTPPaintManager()->SetTheme(nTheme);

	XTPControlTheme  nControlsTheme = m_nTheme == xtpThemeNativeWinXP? xtpControlThemeOffice2000: m_nTheme == xtpThemeOffice2000? xtpControlThemeOffice2000:
		m_nTheme == xtpThemeOfficeXP? xtpControlThemeOfficeXP: xtpControlThemeOffice2003;

	SendMessageToDescendants(WM_XTP_SETCONTROLTHEME, nControlsTheme, 0);

	if ( m_nTheme == xtpThemeNativeWinXP)
	{
		m_wndOutlookBar.SetTheme(xtpTaskPanelThemeNativeWinXP);
	}
	else if ( m_nTheme == xtpThemeOffice2000)
	{
		m_wndOutlookBar.SetTheme(xtpTaskPanelThemeListView);
	}
	else if ( m_nTheme == xtpThemeOfficeXP)
	{
		m_wndOutlookBar.SetTheme(xtpTaskPanelThemeListViewOfficeXP);
	}
	else
	{
		m_wndOutlookBar.SetTheme(xtpTaskPanelThemeShortcutBarOffice2003);
	}

	GetCommandBars()->RedrawCommandBars();
	RedrawWindow(NULL, NULL,
		RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
	RecalcLayout();
	MoveWindow(CXTPWindowRect(this));
	m_wndOutlookBar.Reposition(FALSE);
}


BOOL CXtremeMDIFrameWnd::InitializeOutlookBar()
{
	return TRUE;
}


BOOL CXtremeMDIFrameWnd::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CXTPMDIFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.lpszClass = _T("XTPMainFrame");
	cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;


	CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass, 
		CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));


	return TRUE;
}

void CXtremeMDIFrameWnd::OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState)
{
// Toggle CommandBars
	GetCommandBars()->OnSetPreviewMode(bPreview);

// Toggle Tab Client
	m_wndClient.ShowWorkspace(!bPreview);

	CMDIFrameWnd::OnSetPreviewMode(bPreview, pState);
}

void CXtremeMDIFrameWnd::OnOutbarRButtonDown(CXTPTaskPanelItem* pItem)
{
}


LRESULT CXtremeMDIFrameWnd::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
{
	if (wParam == XTP_DPN_SHOWWINDOW)
	{
		CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;

		if (!pPane->IsValid())
		{
			switch (pPane->GetID())
			{
				case 9001:
					pPane->Attach(&m_wndOutlookBar);
					break;
			}
		}
		return 1;
	}
	return 0;
}


int CXtremeMDIFrameWnd::GetMDIFrameShowType(void)
{
	return m_ShowType;
}


// GetStatusBar
CXTPStatusBar * CXtremeMDIFrameWnd::GetStatusBar(void)
{
	if(m_wndStatusBar.GetSafeHwnd() == NULL)
	{
		return NULL;
	}
	else
	{
		return &m_wndStatusBar;
	}
}
